package com.qf.interceptor;


import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 公用常量
 * @Data: 2022/9/6 14:09
 * @Pacakge: com.qf.interceptor
 * @ClassName: MyInterceptor
 * @Author: fan
 */

public class MyInterceptor implements HandlerInterceptor {
    //ctrl+o重写

    /**
     * 预处理 controller方法之前执行这个方法
     * 相当于aop中的前置通知
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        System.out.println("preHandle执行了....");
        return true;
    }

    /**
     * 后处理 controller方法之后执行这个方法
     * 相当于AOP中的后置通知
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
            throws Exception {
        System.out.println("postHandle执行了...");

    }

    /**
     * 页面执行完执行这个方法
     * 相当于AOP中的最终通知
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        System.out.println("afterCompletion执行了...");
    }
}
